from pathlib import Path

from docx import Document

from content_generator import generate_content
from framework_generator import generate_front_page
from project_constructor import construct_data
from template_compiler import compile_template


def main(report_type_cn, project_id, version):
    report_type_list = {
        "项目建议书": "project_proposal",
        "县域规划报告": "county_planning"
    }
    report_type = report_type_list[report_type_cn]
    root_path = Path.cwd()
    template_json_path = root_path / Path(f"template/template_{report_type}.json")
    data_json_path = root_path / Path(f"json/{report_type}/{project_id}/data_v{version}.json")
    result_json_path = root_path / Path(f"json/{report_type}/{project_id}/result_v{version}.json")
    save_path = root_path / Path(f"result/{report_type}/{project_id}_v{version}.docx")
    project = construct_data(data_json_path)
    compile_template(template_json_path, data_json_path, result_json_path)
    document = Document()
    document = generate_front_page(document, project, report_type, report_type_cn)
    document.add_page_break()
    document = generate_content(document, result_json_path, data_json_path)
    document.save(save_path)


if __name__ == "__main__":
    report_type_cn = "项目建议书"
    project_id = "202204250001"
    version = "001"
    main(report_type_cn, project_id, version)
